package com.zf.aliyun.sms.controller;

import com.zf.aliyun.sms.service.AliyunSmsService;
import com.zf.common.core.result.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 验证码接口
 */
@RestController
@RequestMapping("/aliyun-sms")
public class AliyunSmsController {
    @Autowired
    private AliyunSmsService aliyunSmsService;

    /**
     * 发送短信验证码
     *
     * @param phone 手机号
     */
    @GetMapping("/sendMsgCode")
    public RestResponse<?> sendMsgCode(@RequestParam(name = "phone") String phone) throws Exception {
        return RestResponse.judge(aliyunSmsService.sendMsgCode(phone));
    }

    /**
     * 校验验证码是否正确
     * @param phone 手机号
     * @param code 验证码
     */
    @GetMapping("/verifyCode")
    public RestResponse<?> verifyCode(@RequestParam(name = "phone") String phone, @RequestParam(name = "code") String code) {
        return RestResponse.judge(aliyunSmsService.verifyMsgCode(phone, code));
    }

}
